***Note: replicators should set directory to open data 
*cd ""

*Figure 5

use "ESS.dta", clear
  
*First, weakly Monotonic		

keep if Monotonic==1

drop eduyrs
g eduyrs = total_eduyrs
sum eduyrs, det
replace eduyrs = eduyrs - `r(mean)'
label var eduyrs "Demeaned years of education"
    grstyle init
 grstyle set legend 2,  nobox
 grstyle set size 8pt: tick_label key_label
 grstyle set size 12pt: heading
 grstyle set size 10pt: subheading axis_title 
 grstyle set graphsize 13cm 13cm
	 
rdplot eduyrs r if  r>-21 & r<21,  weights(dweight)  c(0) p(3) lowerend(-20) upperend(19) numbinl(20) numbinr(20)   ci(95) col.dots(black)  col.lines = NULL lwidth(thick)   graph_options(graphregion(fcolor(white) lcolor(white)  )   ylab(,nogrid) title("{bf:{it:{bf:Weak}} monotonicity}") ytitle("Years of schooling (centered)") xtitle("Cohort relative to reform") legend(position(12) rows(1) span )  ylabel(#3) note("Based on IMSE-optimal binning and triangular kernel weights. 95% confidence interval.", size(vsmall) span  ) )  
graph save "Graph/Figure5a", replace 
 

*Strongly Monotonic

use "ESS.dta", clear		

keep if Strong==1

drop eduyrs
g eduyrs = total_eduyrs
sum eduyrs, det
replace eduyrs = eduyrs - `r(mean)'
label var eduyrs "Demeaned years of education"

    grstyle init
 grstyle set legend 2,  nobox
 grstyle set size 8pt: tick_label key_label
 grstyle set size 12pt: heading
 grstyle set size 10pt: subheading axis_title 
 grstyle set graphsize 13cm 13cm
 


rdplot eduyrs r if  r>-21 & r<21,  weights(dweight)  c(0) p(3) lowerend(-20) upperend(19) numbinl(20) numbinr(20)   ci(95)  col.dots(black)  col.lines = NULL lwidth(thick)   graph_options(graphregion(fcolor(white) lcolor(white) )   ylab(,nogrid) title("{bf:Strong monotonicity}")  xtitle("Cohort relative to reform")  legend(position(12) rows(1) span ) ytitle("Years of schooling (centered)") ylabel(#3) note("Based on IMSE-optimal binning and triangular kernel weights. 95% confidence interval.", size(vsmall) span  ) )
graph save "Graph/Figure5b", replace 

          		   grstyle init
grstyle set graphsize 16cm 24cm
 grc1leg  "Graph/Figure5a.gph" "Graph/Figure5b.gph",  cols(2) row(1) imargin(l=0 r=0 b=0)  ring(1) pos(12)
 graph export "Graph/Figure5.tif", replace
 erase "Graph/Figure5a.gph"
 erase "Graph/Figure5b.gph"
